package com.WFinstitute.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.WFinstitute.domain.News;
import com.WFinstitute.domain.Scholar;
import com.WFinstitute.domain.ScholarArticle;
import com.WFinstitute.service.NewsService;
import com.WFinstitute.service.ScholarArticleService;
import com.WFinstitute.service.ScholarService;
import com.WFinstitute.util.Page;



/**
 * 
 * @author 匹夫
 * @date 2016-7-15 下午1:29:33
 * @function 测试jpa类
 */

@Controller
@RequestMapping("/")
public class HomeController {
	@Resource
	private ScholarService  scholarService;
	
	@Resource
	private NewsService  newsService;
	
	@Resource
	private ScholarArticleService  scholarArticleService;
	
	/**
	 * 【前台页面】  到首页
	 * @param response
	 * @param request
	 * @return
	 */
	@RequestMapping("/")
	public String main(HttpServletResponse response,HttpServletRequest request){
		//学者集合
		request.setAttribute("scholarList", scholarList(response,request));
		//新闻集合
		request.setAttribute("newsList", newsList(response,request));
		//学者文章集合
		request.setAttribute("scholararticleList", scholararticleList(response,request));
		return "/WEB-INF/views/main.jsp";
	}
	
	   //得到学者信息
		public  List<Scholar>  scholarList(HttpServletResponse response,HttpServletRequest request){
		  List<Scholar> scholarList = scholarService.findScholarList();
		  return scholarList;
	  }
		
	  //得到新闻信息
		public  List<News>  newsList(HttpServletResponse response,HttpServletRequest request){
			//显示最新8条新闻信息
			Page<News> NewsPageList = newsService.findNewsList(8, 1, "");
			  return NewsPageList.getList();
		  }
	 //得到学者文章信息
		public  List<ScholarArticle>  scholararticleList(HttpServletResponse response,HttpServletRequest request){
			//显示最新8条学者文章信息
				Page<ScholarArticle> ScholarArticlePageList = scholarArticleService.findScholarArticleList(8, 1, "");
				  return ScholarArticlePageList.getList();
			  }
	
}
